<?php

namespace App\Http\Controllers;

use App\Models\Comment;
use App\Models\Goods;
use App\Models\GoodsLike;
use App\Models\Order;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;

class IndexController extends Controller
{
    public function upload(Request $request)
    {
        $url = Storage::putFile('public/upload/' . date("Ymd"), $request->file('file'));
        return response(env('APP_URL') . '/storage/' . str_replace('public/', '', $url));
    }

    public function stat(Request $request)
    {
        $user_id = $request->user()->id;
        $comment = Comment::where('user_fid', $user_id)->whereOr('user_id', $user_id)->where('status', 0)->count();
        $goods_like = GoodsLike::where('user_fid', $user_id)->where('status', 0)->count();
        $order = Order::where('user_id', $user_id)->whereIn('status', [0, 1, 2, 3])->pluck('status')->toArray();
        $order = array_count_values($order);
        return $this->response(compact('comment', 'goods_like', 'order'));
    }
}
